//-
// ==========================================================================
// Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors.  All 
// rights reserved.
//
// The coded instructions, statements, computer programs, and/or related 
// material (collectively the "Data") in these files contain unpublished 
// information proprietary to Autodesk, Inc. ("Autodesk") and/or its 
// licensors, which is protected by U.S. and Canadian federal copyright 
// law and by international treaties.
//
// The Data is provided for use exclusively by You. You have the right 
// to use, modify, and incorporate this Data into other products for 
// purposes authorized by the Autodesk software license agreement, 
// without fee.
//
// The copyright notices in the Software and this entire statement, 
// including the above license grant, this restriction and the 
// following disclaimer, must be included in all copies of the 
// Software, in whole or in part, and all derivative works of 
// the Software, unless such copies or derivative works are solely 
// in the form of machine-executable object code generated by a 
// source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 
// AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED 
// WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF 
// NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR 
// PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR 
// TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS 
// BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL, 
// DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK 
// AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY 
// OR PROBABILITY OF SUCH DAMAGES.
//
// ==========================================================================
//+

#include <animEngine.h>

int
main (int argc, char *argv[])
{
	EtChannel *channelList;
	EtChannel *channel;
	EtInt	numCurves;
	EtInt	i;
	EtKey *	key;
	EtTime	time;

	/* make sure we have been given the name of a .anim file */
	if (argc < 2) {
		fprintf (stderr, "##### Usage: %s .anim file\n", argv[0]);
		exit (-1);
	}

	/* read in the list of channels */
	channelList = engineAnimReadCurves (argv[1], &numCurves);
	if (channelList == kEngineNULL) {
		fprintf (stderr, "##### Unable to parse %s\n", argv[1]);
		exit (-1);
	}

	/* print the list of keys for each chanel */
	channel = channelList;
	while (channel != kEngineNULL) {
		if (channel->curve != kEngineNULL) {
			printf ("%s {\n", channel->channel);	/* channel name */
			for (i = 0; i < channel->curve->numKeys; i++) {
				key = &(channel->curve->keyList[i]);
				printf ("  %g %g %g %g %g %g\n",
					key->time, key->value,
					key->inTanX, key->inTanY,
					key->outTanX, key->outTanY
				);
			}
			printf ("}\n");
		}
		channel = channel->next;
	}

	/* evaluate the channels for 180 frames */
	for (time = 0; time <= 180.0; time++) {
		channel = channelList;
		while (channel != kEngineNULL) {
			if (channel->curve != kEngineNULL) {
				/* Note: evaluation is in seconds (hence the / 24.0) */
				printf ("%s %g %g\n",
					channel->channel,
					time / 24.0,
					engineAnimEvaluate (channel->curve, time / 24.0)
				);
			}
			channel = channel->next;
		}
	}

	/* free up the channel list */
	engineAnimFreeChannelList (channelList);

	return (0);
}
